import java.util.Stack;

public class Parenthesis {
    public static boolean chkParenthesis(String A, int n) {
        // write code here
        if(A==null)return false;
        Stack<Character> stack = new Stack<>();
        for(int i =0;i<A.length();i++){
            if(A.charAt(i)=='('){
                System.out.println("==========1");
                stack.push(A.charAt(i));
            }

            else if(A.charAt(i)==')'){
                if(stack.isEmpty())return false;
                System.out.println("==========2");
                char a = stack.peek();
                if(a=='(')stack.pop();
                else return false;
            }
            else  return false;
            
        }
        if(stack.isEmpty()){
            return true;
        }
        else return false;

    }

    public static void main(String[] args) {
        System.out.println(        chkParenthesis("(()())",6));
    }
}